'''
* This is the projet for Brtc LlmOps Platform
* @Author Leon-liao <liaosiliang@alltman.com>
* @Description //TODO 
* @File: 6_study_check_pointer.py
* @Time: 2025/11/4
* @All Rights Reserve By Brtc
'''
import dotenv
from langchain_community.tools import GoogleSerperRun
from langchain_community.tools.openai_dalle_image_generation import OpenAIDALLEImageGenerationTool
from langchain_community.utilities import GoogleSerperAPIWrapper
from langchain_community.utilities.dalle_image_generator import DallEAPIWrapper
from langchain_openai import ChatOpenAI
from langgraph.checkpoint.memory import MemorySaver
from langgraph.prebuilt import create_react_agent
from pydantic import BaseModel, Field
dotenv.load_dotenv()

class GoogleSerperSchema(BaseModel):
    query:str = Field(description="执行谷歌搜索的查询语句")

google_serper = GoogleSerperRun(
    name = "google_serper",
    description = ("一个低成本的谷歌搜索API工具！"),
    args_schema=GoogleSerperSchema,
    api_wrapper=GoogleSerperAPIWrapper(),)

dalle = OpenAIDALLEImageGenerationTool(
    name="openai-dalle",
    api_wrapper=DallEAPIWrapper(model = "dall-e-3")
)

tools = [google_serper, dalle]

# 模型创建
model = ChatOpenAI(model="gpt-4o-mini", temperature=0)
# 使用预构建函数创建智能体
checkpointer = MemorySaver()
config = {"configurable":{"thread_id":9527}}
agent = create_react_agent(model=model,
                           tools=tools,
                           checkpointer=checkpointer)
#4、调用智能体
print(agent.invoke(
    {"messages":[("human", "你好我叫博小睿, 我喜欢篮球 rap 和 街舞！")]},
    config=config
))

print(agent.invoke(
    {"messages":[("human", "你知道我叫什么吗？")]},
    config=config
))